import java.util.Arrays;

public class Test {
    public static void main1(String[] args) {
        TestHeap testHeap=new TestHeap();
        int[] arr = {27,15,19,18,28,34,65,49,25,37};
        testHeap.initHeap(arr);
        testHeap.createHeap();

    }
    public static void SelectSort(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            int min=i;
            for (int j = i+1; j < arr.length; j++) {
                if(arr[j]<arr[min]){
                    min=j;
                }
            }
            swap(arr,min,i);
        }
    }
    public static void SelectSort2(int[] arr){
        int left=0;
        int right=arr.length-1;
        while(left<right){
            int min=left;
            int max=left;
            for (int i = left+1; i <= right; i++) {
                if(arr[i]<arr[min]){
                    min=i;
                }
                if(arr[i]>arr[max]){
                    max=i;
                }
            }
            swap(arr,left,min);
            if(max==left){
                max=min;
            }
            swap(arr,right,max);
            left++;
            right--;
        }
    }
    public static void swap(int[] arr,int i,int j){
        int tmp=arr[i];
        arr[i]=arr[j];
        arr[j]=tmp;
    }

    public static void main(String[] args) {
        int[] arr = {27,15,19,18,28,34,65,49,25,37};
        System.out.println(Arrays.toString(arr));
        SelectSort2(arr);
        System.out.println(Arrays.toString(arr));
    }
}
